﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using static YunRuiFarm.Models.DatabaseModels;

namespace YunRuiFarm.Filters
{
    public class APIFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if(filterContext.ActionDescriptor.GetCustomAttributes(typeof(AllowAnonymousAttribute),true).Any())
            {
                string tempController = filterContext.RouteData.Values["controller"].ToString();
                if (tempController == "YunRuiFarmAPI")
                {
                    String tempToken = filterContext.HttpContext.Request["token"];
                    if (tempToken == null)
                    {
                        HttpContext.Current.Response.Write("<script>alert('请先登录');</script>");
                    }
                }
            }
            
        }
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            
        }
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            
        }
        
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            
        }
    }
}
